package com.qiku.controller;


import com.qiku.domin.PromotionSpace;
import com.qiku.domin.ResponseResult;
import com.qiku.service.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/PromotionSpace")
public class PromotionSpaceController {

    @Autowired
    private PromotionSpaceService promotionSpaceService;


    @RequestMapping(value = "/findAllPromotionSpace" , method = RequestMethod.GET)
    public ResponseResult findAllPromotionSpace(){
        List<PromotionSpace> space = promotionSpaceService.findAllPromotionSpace();
        ResponseResult result = new ResponseResult(true, 200, "响应成功", space);
        return result;
    }


    @PostMapping("/saveOrUpdatePromotionSpace")
    public ResponseResult saveOrUpdatePromotionSpace(@RequestBody PromotionSpace promotionSpace){
        if (null != promotionSpace.getId() && 0 < promotionSpace.getId()){
            // 有id 修改操作
            promotionSpaceService.updatePromotionSpace(promotionSpace);
            ResponseResult result = new ResponseResult(true, 200, "修改成功", null);
            return result;
        }else {
            // 插入操作
            promotionSpaceService.savePromotionSpace(promotionSpace);
            ResponseResult result = new ResponseResult(true, 200, "响应成功", null);
            return result;
        }
    }


    @RequestMapping(value = "/findPromotionSpaceById" , method = RequestMethod.GET)
    public ResponseResult findPromotionSpaceById(@RequestParam Integer id){
        PromotionSpace byId = promotionSpaceService.findPromotionSpaceById(id);
        ResponseResult result = new ResponseResult(true, 200, "响应成功", byId);
        return result;
    }

}
